package com.magicode.cms.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.magicode.cms.common.assist.UtilPath;
import com.magicode.cms.dao.IChannelDao;
import com.magicode.cms.dao.IFilmBoxOfficeDao;
import com.magicode.cms.dao.IFilmTotalBoxOfficeDao;
import com.magicode.cms.entiy.base.Channel;
import com.magicode.cms.entiy.base.FilmBoxOffice;
import com.magicode.cms.entiy.base.FilmTotalBoxOffice;
import com.magicode.cms.service.IChannelService;
import com.magicode.cms.service.IFilmBoxOfficeService;
import com.magicode.cms.service.IFilmTotalBoxOfficeService;

@Service("serviceFilmTotalBoxOffice")
public class FilmTotalBoxOfficeServiceImpl extends BaseServiceImpl<FilmTotalBoxOffice,IFilmTotalBoxOfficeDao> implements IFilmTotalBoxOfficeService,UtilPath{

	@Autowired
	@Qualifier("daoFilmTotalBoxOffice")
	private IFilmTotalBoxOfficeDao totalBoxOfficeDao;
	

	public IFilmTotalBoxOfficeDao getTotalBoxOfficeDao() {
		return totalBoxOfficeDao;
	}

	public void setTotalBoxOfficeDao(IFilmTotalBoxOfficeDao totalBoxOfficeDao) {
		this.totalBoxOfficeDao = totalBoxOfficeDao;
	}

	@Override
	public List<Map<String, Object>> getBeanInfo() {
		List<Map<String, Object>> beaninfo = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(json_key, "statisticsDate");
		map.put(json_title, "年月日");
		map.put("width", 100);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "currentBoxOffice");
		map.put(json_title, "日总票房");
		map.put("width", 100);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "currentSession");
		map.put(json_title, "日总场次");
		map.put("width", 300);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "currentAttendance");
		map.put(json_title, "日观影人次");
		map.put("width", 300);
		beaninfo.add(map);
		
		return beaninfo;
	}
	
	@Override
	public List<Map<String,Object>> select(Map<String,String> querywhere){
		try {
			String hql = this.getHql(querywhere);
			Map<String,String> gridsel = new HashMap<String,String>();
			gridsel.put(field_id, ""+entity_alias_name+".id as id ");
			gridsel.put(field_title, ""+entity_alias_name+".title as title ");
			gridsel.put("parentTitle", " p.title as parentTitle ");
			gridsel.put("orderCode", ""+entity_alias_name+".orderCode as orderCode ");
			return this.queryMapDataList(hql, gridsel,0 , 0);
		} catch (Exception e) {
			e.printStackTrace();
			return new ArrayList<Map<String, Object>>();
		}
	}
	
	@Override
	public String getHql(Map<String, String> map) throws Exception {
		String hql = " from "+com.magicode.cms.entiy.base.FilmTotalBoxOffice.class.getName()+" t"
				+ " left outer join t.source as s "
				+ " left outer join t.author as a"
				+ " where 1 = 1 ";
		if(null!=map && !map.isEmpty()){
			/*if(map.containsKey(field_article_id)){
				hql = hql+" ";
			}*/
			if(map.containsKey(field_id)){
				hql = hql+" and "+entity_alias_name+".id='"+map.get(field_id)+"'";
			}

			/*if(map.containsKey("title")){
				hql = hql+" and "+entity_alias_name+".title like '%"+map.get("title")+"%'";
			}

			if(map.containsKey("subject")){
				hql = hql+" and "+entity_alias_name+".subject like '%"+map.get("subject")+"%'";
			}
			if(map.containsKey("parentId")){
				hql = hql+" and "+entity_alias_name+".parent.id='"+map.get("parentId")+"'";
			}

			if(map.containsKey("type")){
				hql = hql+" and "+entity_alias_name+".type in ("+map.get("type")+")";
			}
			if(map.containsKey("nocode_quicklytReport")){
				String pram1 = map.get("nocode_quicklytReport");
				hql = hql+" and "+entity_alias_name+".code not in ('"+pram1+"')";
			}*/
			System.out.println(hql);
		}
		return hql;
	}
	@Override
	public List<Map<String, Object>> grid(Map<String, String> querywhere) {
			
		try {
			Integer start = this.getGridStartOrSize(querywhere, 0, field_grid_start);
			Integer size = this.getGridStartOrSize(querywhere,0, field_grid_size);
			String hql = this.getHql(querywhere);
		//	hql += "  order by "+entity_alias_name+".orderCode asc "; 
			//hql += "  ,"+entity_alias_name+".createTime desc "; 
			Map<String,String> gridsel = new HashMap<String,String>();
			gridsel.put(field_id, ""+entity_alias_name+".id as id ");
//			gridsel.put("titleCn", " p.titleCn as titleCn ");
			gridsel.put("statisticsDate", ""+entity_alias_name+".statisticsDate as statisticsDate ");
			gridsel.put("currentBoxOffice", ""+entity_alias_name+".currentBoxOffice as currentBoxOffice ");
			gridsel.put("currentSession", ""+entity_alias_name+".currentSession as currentSession ");
			gridsel.put("currentAttendance", ""+entity_alias_name+".currentAttendance as currentAttendance ");
			return this.queryMapDataList(hql, gridsel,start , size);
		} catch (Exception e) {
			return new ArrayList<Map<String, Object>>();
		}
		
	}

	@Override
	public IFilmTotalBoxOfficeDao getDao() throws Exception {
		// TODO Auto-generated method stub
		return totalBoxOfficeDao;
	}
	

}
